#pragma once

#include "MIMXRT1021.h"

/* flag to gpio_configure */
#define GPIO_IMXRT_AF (0x1 << 16)
#define GPIO_IMXRT_OD (0x2 << 16)
#define GPIO_IMXRT_AFn(n) ((n) << 24)

/* gpio port/pin is packed into a single unsigned int in 16x:8port:8pin format */
#define GPIO(port, pin) ((unsigned int)(((port) << 8) | (pin)))

#define GPIO_TO_PIN_MASK(gpio) ((unsigned int)( 1 << ((gpio) & 0x0f)))

#define GPIO_PORT(gpio) (((gpio) >> 8) & 0xff)
#define GPIO_PIN(gpio) ((gpio) & 0xff)
#define GPIO_AFNUM(gpio) (((gpio) >> 24) & 0xf)

#define GPIO_PORT_0 0
#define GPIO_PORT_1 1
#define GPIO_PORT_2 2
#define GPIO_PORT_3 3
#define GPIO_PORT_4 4
#define GPIO_PORT_5 5



enum
{
  ALT0,
  ALT1,
  ALT2,
  ALT3,
  ALT4,
  ALT5,
  ALT6,
  ALT7,
  ALT_MAX,
};


enum
{
  HYS_EN          = 1<<IOMUXC_SW_PAD_CTL_PAD_HYS_SHIFT,   //滞后使能

  PULLDOWN_100K   = 0<<IOMUXC_SW_PAD_CTL_PAD_PUS_SHIFT,   //端口为输入时有效
  PULLUP_47K      = 1<<IOMUXC_SW_PAD_CTL_PAD_PUS_SHIFT,   //端口为输入时有效
  PULLUP_100K     = 2<<IOMUXC_SW_PAD_CTL_PAD_PUS_SHIFT,   //端口为输入时有效
  PULLUP_22K      = 3<<IOMUXC_SW_PAD_CTL_PAD_PUS_SHIFT,   //端口为输入时有效

  PULL_EN         = 1<<IOMUXC_SW_PAD_CTL_PAD_PKE_SHIFT | 1<<IOMUXC_SW_PAD_CTL_PAD_PUE_SHIFT,
  KEEPER_EN       = 1<<IOMUXC_SW_PAD_CTL_PAD_PKE_SHIFT,   //保持器使能

  OD_EN           = 1<<IOMUXC_SW_PAD_CTL_PAD_ODE_SHIFT,   //开漏使能

  SPEED_50MHZ     = 0<<IOMUXC_SW_PAD_CTL_PAD_SPEED_SHIFT,
  SPEED_100MHZ    = 1<<IOMUXC_SW_PAD_CTL_PAD_SPEED_SHIFT,
  SPEED_200MHZ    = 3<<IOMUXC_SW_PAD_CTL_PAD_SPEED_SHIFT,

  DSE_DIS         = 0<<IOMUXC_SW_PAD_CTL_PAD_DSE_SHIFT,   //禁用输出强度设置
  DSE_R0          = 1<<IOMUXC_SW_PAD_CTL_PAD_DSE_SHIFT,   //3.3V时150ohm  1.8V时260ohm
  DSE_R0_2        = 2<<IOMUXC_SW_PAD_CTL_PAD_DSE_SHIFT,   //R/2
  DSE_R0_3        = 3<<IOMUXC_SW_PAD_CTL_PAD_DSE_SHIFT,   //R/3
  DSE_R0_4        = 4<<IOMUXC_SW_PAD_CTL_PAD_DSE_SHIFT,   //R/4
  DSE_R0_5        = 5<<IOMUXC_SW_PAD_CTL_PAD_DSE_SHIFT,   //R/5
  DSE_R0_6        = 6<<IOMUXC_SW_PAD_CTL_PAD_DSE_SHIFT,   //R/6
  DSE_R0_7        = 7<<IOMUXC_SW_PAD_CTL_PAD_DSE_SHIFT,   //R/7
	
  SRE_SLOW        = 0<<IOMUXC_SW_PAD_CTL_PAD_SRE_SHIFT,
  SRE_FAST        = 1<<IOMUXC_SW_PAD_CTL_PAD_SRE_SHIFT,

};



void imxrt_iomuxc_pinconf(unsigned nr, uint8_t alt, uint32_t pinconf);





